#include "master.h"

CMaster::CMaster(void)
{
	currentMode = MODE_SLEEP;
}

CMaster::~CMaster(void)
{
}

void CMaster::parseMessage(Message& msg, vector<Message>& retMsg)
{
	Message m;
	switch(msg.MsgCode)
	{
	case MSG_INIT:
		currentMode = MODE_SLEEP;
		break;
	case MSG_QUEUE_EMPTY:
			switch(currentMode)
			{
			case MODE_SLEEP:
					currentMode = MODE_UPDATE;
					m.Set("Master", "All", MSG_UPDATE);
					retMsg.push_back(m);
				break;
			case MODE_UPDATE:
					currentMode = MODE_DRAW;
					m.Set("Master", "Display", MSG_DRAW);
					retMsg.push_back(m);
				break;
			case MODE_DRAW:
					currentMode = MODE_SLEEP;
					m.Set("Master", "Timer", MSG_TIMER_WAIT);
					retMsg.push_back(m);
				break;
			}
			break;
/*
	case MSG_TIMER:
		currentMode = MODE_UPDATE;
		m.Set("Master", "All", MSG_UPDATE);
		retMsg.push_back(m);
		break;
*/
	}
}





**********
			PKeys k = dynamic_pointer_cast<CKeys>(msg.Data);
			
			if(k->keys.find('1')!=string::npos)
			{
				Rotate(ROT_LEFT);
			}
			else if(k->keys.find('3')!=string::npos)
			{
				Rotate(ROT_RIGHT);
			}
			else if(k->keys.find('9')!=string::npos)
			{
				Rotate(ROT_CLKWISE);
			}
			else if(k->keys.find('7')!=string::npos)
			{
				Rotate(ROT_CCLKWISE);
			}
*********


	case MSG_PRESSED_KEYS:
		{
			Message m;
			PKeys k = dynamic_pointer_cast<CKeys>(msg.Data);

			if(k->keys.find('1')!=string::npos)
			{
				m.Set("Hero","Cube",MSG_GET_SIZE);
				retMsg.push_back(m);
				m.Set("Hero","Hero",MSG_ROT_LEFT);
				retMsg.push_back(m);
				m.Set("Hero","Cube",MSG_SET_CRSECTION,heroCoords);
				retMsg.push_back(m);
				m.Set("Hero","Cube",MSG_GET_CRSECTION);
				retMsg.push_back(m);
			}
			else if(k->keys.find('3')!=string::npos)
			{
				m.Set("Hero","Cube",MSG_GET_SIZE);
				retMsg.push_back(m);
				m.Set("Hero","Hero",MSG_ROT_RIGHT);
				retMsg.push_back(m);
				m.Set("Hero","Cube",MSG_SET_CRSECTION,heroCoords);
				retMsg.push_back(m);
				m.Set("Hero","Cube",MSG_GET_CRSECTION);
				retMsg.push_back(m);
			}
			else if(k->keys.find('9')!=string::npos)
			{
				m.Set("Hero","Cube",MSG_GET_SIZE);
				retMsg.push_back(m);
				m.Set("Hero","Hero",MSG_ROT_CLKWISE);
				retMsg.push_back(m);
				m.Set("Hero","Cube",MSG_SET_CRSECTION,heroCoords);
				retMsg.push_back(m);
				m.Set("Hero","Cube",MSG_GET_CRSECTION);
				retMsg.push_back(m);
			}
			else if(k->keys.find('7')!=string::npos)
			{
				m.Set("Hero","Cube",MSG_GET_SIZE);
				retMsg.push_back(m);
				m.Set("Hero","Hero",MSG_ROT_CCLKWISE);
				retMsg.push_back(m);
				m.Set("Hero","Cube",MSG_SET_CRSECTION,heroCoords);
				retMsg.push_back(m);
				m.Set("Hero","Cube",MSG_GET_CRSECTION);
				retMsg.push_back(m);
			}
			else if(k->keys.find('4')!=string::npos)
			{
				Move(MOV_LEFT);
			}
			else if(k->keys.find('6')!=string::npos)
			{
				Move(MOV_RIGHT);
			}
			else if(k->keys.find('8')!=string::npos)
			{
				Move(MOV_UP);
			}
		}

*********